<template>
    <div class="app-container">
  
      <div class="filter-container">

        <el-date-picker
            v-model="listQuery.date"
            type="date"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions2"
            placeholder="选择日期">
        </el-date-picker>

        <el-input
          v-model="listQuery.oaid"
          placeholder="请输入设备id"
          style="width: 220px;"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
        <el-button
         plain size="small"
          v-waves
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >搜索</el-button>

        <el-button
         plain size="small"
          v-waves
          class="filter-item btn"
          type="primary"
          icon="el-icon-refresh"
          @click="handleCancel"
        >重置</el-button>
      </div>
      
      <el-table
            v-loading="listLoading"
            :data="list"
            border
            fit
            highlight-current-row
            style="width: 100%;"
          >
          <el-table-column type="expand">
              <template slot-scope="props">
                <el-form label-position="left" inline class="demo-table-expand">
                  <el-form-item label="hap链接：">
                    <json-viewer 
                      :value="props.row.device_info" 
                      :expand-depth="100" 
                      copyable 
                        sort
                      theme="my-awesome-json-theme">
                    </json-viewer> 
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>

            <el-table-column label="设备id" porp="oaid" min-width="50" align="center">
              <template slot-scope="{row}">
                <span>{{ row.oaid }}</span> 
              </template>
            </el-table-column>
            <el-table-column label="包" porp="oaid" min-width="50" align="center">
              <template slot-scope="{row}">
                <span>{{ pkgs[row.pkg] }}</span> 
              </template>
            </el-table-column>
            <el-table-column label="厂商" porp="oaid" min-width="50" align="center">
              <template slot-scope="{row}">
                <span>{{ brand1[row.brand] }}</span> 
              </template>
            </el-table-column>

            <!-- <el-table-column label="设备详情" min-width="" align="center">
              <template slot-scope="{row}">
                <span>{{ row.device_info }}</span> 
                <el-popover
                  placement="bottom"
                  title="设备详情"
                  width="800"
                  trigger="manual"
                  :content="row.device_info "
                  v-model="visible">
                  <el-button slot="reference" @click="visible = !visible">点击查看</el-button>
                </el-popover>
              </template>
            </el-table-column> -->

            <el-table-column label="创建时间" min-width="" align="center">
              <template slot-scope="{row}">
                <span>{{ row.create_time }}</span>
              </template>
            </el-table-column>

          </el-table>
      
          <pagination
            v-show="total > 0"
            :total="total"
            class="pageShow"
            :page.sync="listQuery.page"
            :limit.sync="listQuery.limit"
            @pagination="getList"
          />


      <!-- <json-viewer 
      :value="data" 
      :expand-depth="100" 
      copyable 
        sort
      theme="my-awesome-json-theme"></json-viewer> -->
    </div>
  </template>
  
  <script>
  import {
    getPkgList,
    getUserDevrice
  } from "@/api/adv_admin/config";

  import waves from "@/directive/waves"; // waves directive
  import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

  import JsonViewer from 'vue-json-viewer'
  import { brand1 } from '@/utils/index.js'
  export default {
    name: "Control",
    components: { Pagination, JsonViewer },
    directives: { waves },
    data() {
      return {
        brand1,
        tableKey: 0,
        total: 0,
        listLoading: false,
        listQuery: {
          page: 1,
          limit: 20,
          oaid: "",
          data: ''
        },
        error_type: {},
        pkgs: {},
        list: {},
        total: 0,
        pickerOptions2: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
        }
      };
    },
    created() {
    },
    mounted() {
      this.getPkgs()
    },
    methods: {
      getPkgs(){
        getPkgList().then((res)=>{
          this.pkgs = res.DATA.list
        })
      },
      getList() {
        this.listLoading = true;
        getUserDevrice(this.listQuery).then((response) => {
          this.list = response.DATA.list;
          this.total = response.DATA.total;
          this.listLoading = false;
        });
      },
      handleFilter() {
        this.listQuery.page = 1;
        this.getList();
      },
      handleCancel(){
        this.listQuery = {
          page: 1,
          limit: 20,
          oaid: "",
          data: ''
        }
        this.getList()
      }
    
    },
  };
  </script>
  
  <style lang="scss">

   // values are default one from jv-light template
.my-awesome-json-theme {
  background: #fff;
  white-space: nowrap;
  color: #525252;
  font-size: 14px;
  font-family: Consolas, Menlo, Courier, monospace;

  .jv-ellipsis {
    color: #999;
    background-color: #eee;
    display: inline-block;
    line-height: 0.9;
    font-size: 0.9em;
    padding: 0px 4px 2px 4px;
    border-radius: 3px;
    vertical-align: 2px;
    cursor: pointer;
    user-select: none;
  }
  .jv-button { color: #49b3ff }
  .jv-key { color: #111111 }
  .jv-item {
    &.jv-array { color: #111111 }
    &.jv-boolean { color: #fc1e70 }
    &.jv-function { color: #067bca }
    &.jv-number { color: #fc1e70 }
    &.jv-number-float { color: #fc1e70 }
    &.jv-number-integer { color: #fc1e70 }
    &.jv-object { color: #111111 }
    &.jv-undefined { color: #e08331 }
    &.jv-string {
      color: #42b983;
      word-break: break-word;
      white-space: normal;
    }
  }
  .jv-code {
    .jv-toggle {
      &:before {
        padding: 0px 2px;
        border-radius: 2px;
      }
      &:hover {
        &:before {
          background: #eee;
        }
      }
    }
  }
}
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 16px;
    color: #ccc;
    cursor: pointer;
    user-select: none;
  }
  .push {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    margin-left: 5px;
  }
  .pageHidden {
    display: none;
  }
  .btn {
    margin-left: 0;
  }
  .fullwidth {
    width: 450px;
    margin-left: 50px;
  }
  @media (max-width: 550px) {
    .pageShow {
      display: none;
    }
    .pageHidden {
      display: block;
    }
    .fullwidth {
      width: 100%;
      margin-left: 0;
    }
  }
 

  </style>
  